var t = getApp(),
  e = t.requirejs("core");
Page({
  data: {
    icons: t.requirejs("icons"),
    success: false,
    successData: {},
    button_color: t.config.button_color
  },
  onLoad: function (ev) {
    e.setting();
    this.setData({
      options: ev,
      button_color: getApp().config.button_color,
      font_color: getApp().config.font_color,
      config: getApp().config
    })
      
  },
  onShow: function () {
    this.get_list();
    console.log("张孟辉")
  },
  to_home: function () {
    e.jump('/yb_mingpian/pages/shop/index',3)
  },
  /**
   *获取订单信息
   * @param order_id 订单id
   * @return array
   */
  get_list: function () {
    var t = this;
    e.get("pay/OrderInfo", { order_id: t.data.options.id}, function (i) {
        console.log("info",i);
      0 == i.code ? (
        t.setData({
          list: i.info,
          show: true
        })
      ): (e.alert(i.msg), setTimeout(function () {
        wx.navigateBack()
      }, 1e3))
        
    })
  },
  // 再去逛逛
  viewAround: function () {
    wx.navigateBack();
  },
  /**
   *调用支付
   * @param out_trade_no 订单号
   * @param openid
   * @return array
   */
  pay: function (k) {
    var o = this;
    o.setData({
      formid: k.detail.formId
    })
    e.get("Pay/Pay", { 
      out_trade_no: o.data.list.out_trade_no,
      openid:getApp().getCache("userinfo").openid
      }, function (t) {
        console.log(t)
      0 == t.code ? (
        wx.requestPayment({
          'timeStamp': t.info.timeStamp,
          'nonceStr': t.info.nonceStr,
          'package': t.info.package,
          'signType': 'MD5',
          'paySign': t.info.paySign,
          'success': function (res) {
            if(res.errMsg == "requestPayment:ok"){
             wx.setNavigationBarTitle({
                title: "支付成功"
              });
              o.setData({
                success: true,
                "list.order_status":1
              });
              //推送
              e.get('Wxpush/PayOrderPush', {
                out_trade_no: o.data.list.out_trade_no,
                formid: o.data.formid,
                uid: getApp().getCache("userinfo").uid
              }, function (t) {
                console.log(t)
              });
            }else{
              e.alert('支付失败！')
              wx.redirectTo({
                url: "/yb_mingpian/pages/order/index"
              })
            }
          },
          'fail': function (res) {
            e.alert('您已经取消支付！')
            wx.redirectTo({
              url: "/yb_mingpian/pages/order/index"
            })
          }
        })
      ) : (e.alert(t.msg), setTimeout(function () {
        wx.navigateBack()
      }, 1e3))

    })
      return;
   
  },
  
  phone: function (t) {
    e.phone(t)
  }
})